package com.osdp.uc.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.osdp.uc.service.IUcTitleService;
import com.osdp.uc.vo.UcTitleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "岗位信息")
@RestController
@RequestMapping("/uc/title")
public class UcTitleController {

    @Autowired
    private IUcTitleService titleService;

    @RequestMapping(value = "/pageList", method = RequestMethod.GET)
    @ApiOperation(value = "职务列表", tags = "职务列表")
    public IPage<UcTitleVo> pageList(UcTitleVo titleVo,
                                     @RequestParam(name = "pageNo", defaultValue = "1") int pageNo,
                                     @RequestParam(name = "pageSize", defaultValue = "10") int pageSize){
        return titleService.pageList(titleVo, new Page<>(pageNo,pageSize));
    }

    @RequestMapping(value = "/allList", method = RequestMethod.GET)
    @ApiOperation(value = "查询职务列表", tags = "查询职务列表")
    public List<UcTitleVo> queryAllList(@RequestParam(name = "titleName", required = false) String titleName,
                                        @RequestParam(name = "titleCode", required = false) String titleCode){
        return titleService.queryAllTitle(titleName,titleCode);
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation("新增职务")
    public boolean insert(@RequestBody UcTitleVo titleVo){
        return titleService.insertTitile(titleVo);
    }

    @PutMapping("/update")
    @ApiOperation("修改职务")
    public boolean update(@RequestBody UcTitleVo titleVo){
        return titleService.updateTitile(titleVo);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除职务")
    public boolean delete(@RequestParam(name = "id", required = true) String id) {
        return titleService.deleteTitile(id);
    }

    @RequestMapping(value = "/getById", method = RequestMethod.GET)
    @ApiOperation("根据ID获取对象")
    public UcTitleVo getById(@RequestParam(name = "id", required = true) String id){
        return titleService.getByTitileId(id);
    }
}
